﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;

namespace SalePartial.Model
{

    public class XPCompanyCertInfo
    {
        // Methods
        public XPCompanyCertInfo()
        {
            this._companyID = Guid.Empty;
            this._certName = string.Empty;
            this._certFileName = string.Empty;
            this._certFileContentType = string.Empty;
            this._createUserID = Guid.Empty;
            this._moderateUserID = Guid.Empty;
            this._comments = string.Empty;
            this._certID = Guid.NewGuid();
            this._createDate = DateTime.Now;
            this._lastUpdateDate = DateTime.Now;
            this._moderateDate = new DateTime(0x7ad565b72888000L);
        }

        public XPCompanyCertInfo(SqlDataReader reader)
        {
            this._companyID = Guid.Empty;
            this._certName = string.Empty;
            this._certFileName = string.Empty;
            this._certFileContentType = string.Empty;
            this._createUserID = Guid.Empty;
            this._moderateUserID = Guid.Empty;
            this._comments = string.Empty;
            this.LoadFromReader(reader);
        }

        //public XPCompanyCertInfo(Guid id)
        //{
        //    this._companyID = Guid.Empty;
        //    this._certName = string.Empty;
        //    this._certFileName = string.Empty;
        //    this._certFileContentType = string.Empty;
        //    this._createUserID = Guid.Empty;
        //    this._moderateUserID = Guid.Empty;
        //    this._comments = string.Empty;
        //    SqlDataReader reader = XPCompanyCertUtility.SelectReader(id);
        //    if (reader.Read()) {
        //        this.LoadFromReader(reader);
        //        reader.Close();
        //    } else {
        //        if (!reader.IsClosed) {
        //            reader.Close();
        //        }
        //        throw new ApplicationException("XPCompanyCerts does not exist.");
        //    }
        //}



        protected void LoadFromReader(SqlDataReader reader)
        {
            if ((!Information.IsNothing(reader) && !reader.IsClosed))
            {
                this._certID = reader.GetGuid(0);
                this._companyID = reader.GetGuid(1);
                this._certType = reader.GetInt16(2);
                this._certName = reader.GetString(3);
                this._certFileName = reader.GetString(4);
                this._certFileContentType = reader.GetString(5);
                this._certFileSize = reader.GetInt32(6);
                this._certFileData = (byte[])reader[7];
                this._createUserID = reader.GetGuid(8);
                this._createDate = reader.GetDateTime(9);
                this._lastUpdateDate = reader.GetDateTime(10);
                if (!reader.IsDBNull(11))
                {
                    this._moderateUserID = reader.GetGuid(11);
                }
                if (!reader.IsDBNull(12))
                {
                    this._moderateStatus = reader.GetInt32(12);
                }
                if (!reader.IsDBNull(13))
                {
                    this._moderateDate = reader.GetDateTime(13);
                }
                if (!reader.IsDBNull(14))
                {
                    this._comments = reader.GetString(14);
                }
            }
        }

        public static XPCompanyCertInfo NewXPCompanyCert(Guid id)
        {
            return new XPCompanyCertInfo { _certID = id };
        }

        // Properties
        public string CertFileContentType
        {
            get { return this._certFileContentType; }
            set { this._certFileContentType = value; }
        }

        public byte[] CertFileData
        {
            get { return this._certFileData; }
            set { this._certFileData = value; }
        }

        public string CertFileName
        {
            get { return this._certFileName; }
            set { this._certFileName = value; }
        }

        public int CertFileSize
        {
            get { return this._certFileSize; }
            set { this._certFileSize = value; }
        }

        public Guid CertID
        {
            get { return this._certID; }
            set { this._certID = value; }
        }

        public string CertName
        {
            get { return this._certName; }
            set { this._certName = value; }
        }

        public short CertType
        {
            get { return this._certType; }
            set { this._certType = value; }
        }

        public string Comments
        {
            get { return this._comments; }
            set { this._comments = value; }
        }

        public Guid CompanyID
        {
            get { return this._companyID; }
            set { this._companyID = value; }
        }

        public DateTime CreateDate
        {
            get { return this._createDate; }
            set { this._createDate = value; }
        }

        public Guid CreateUserID
        {
            get { return this._createUserID; }
            set { this._createUserID = value; }
        }

        public DateTime LastUpdateDate
        {
            get { return this._lastUpdateDate; }
            set { this._lastUpdateDate = value; }
        }

        public DateTime ModerateDate
        {
            get { return this._moderateDate; }
            set { this._moderateDate = value; }
        }

        public int ModerateStatus
        {
            get { return this._moderateStatus; }
            set { this._moderateStatus = value; }
        }

        public Guid ModerateUserID
        {
            get { return this._moderateUserID; }
            set { this._moderateUserID = value; }
        }


        // Fields
        private string _certFileContentType;
        private byte[] _certFileData;
        private string _certFileName;
        private int _certFileSize;
        private Guid _certID;
        private string _certName;
        private short _certType;
        private string _comments;
        private Guid _companyID;
        private DateTime _createDate;
        private Guid _createUserID;
        private DateTime _lastUpdateDate;
        private DateTime _moderateDate;
        private int _moderateStatus;
        private Guid _moderateUserID;
    }
}

